/**
 * 作者：陈文斌 on 2019/1/14.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/VisitorRecord/visitor_type_model.dart';
import 'package:crm/view/Tile/list_tile_text.dart';
import 'package:crm/view/Tile/tile_normal.dart';
import 'package:crm/view/GridView/grid_view_add_image.dart';
import 'package:crm/page/VisitorRecord/visitor_type_page.dart';
import 'package:crm/view/AppBar/custom_app_bar.dart';

const String Title = '添加外勤拜访';

class AddVisitorRecordPage extends StatefulWidget {
  final String customerName;

  AddVisitorRecordPage({
    Key key,
    this.customerName,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _AddVisitorRecordPageState();
  }
}

class _AddVisitorRecordPageState extends State<AddVisitorRecordPage> {
  /// 拜访详情
  String _visitorDetails = '';
  /// 拜访类型
  VisitorTypeModel _visitorType;


  @override
  void initState() {
    super.initState();
    _visitorType = VisitorTypeModel.fromJson({});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        title: Title,
      ),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: ListView(
          children: <Widget>[
            Padding(padding: EdgeInsets.only(top: 10)),
            ListTileText(
              title: Text('拜访客户'),
              content: widget.customerName ?? '',
              dividerVisible: true,
              onTap: () {
                print('带入值');
              },
            ),
            Padding(padding: EdgeInsets.only(top: 10)),
            ListTileText(
              title: Text('拜访类型'),
              content: _visitorType.content ?? ' ',
              requiredVisible: false,
              onTap: () {
                print('拜访类型');
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => VisitorTypePage(
                          confirmCallback: (VisitorTypeModel visitorType) {
                            _visitorType = visitorType;
                          },
                        ),
                  ),
                );
              },
            ),
            ListTileText(
              title: Text('拜访人'),
              content: ' ',
              requiredVisible: false,
              onTap: () {
                print('拜访人');
              },
            ),
            TileNormal(
              title: Expanded(
                child: Text(
                  '福建省泉州市晋江市龙湖镇后宅村宗兴大厦',
                  style: TextStyle(
                    color: AppColors.MainColor,
                    fontSize: AppFontSizes.Font13,
                    fontFamily: AppFontFamilies.PingFangSC,
                  ),
                  overflow: TextOverflow.ellipsis,
                  maxLines: 1,
                ),
              ),
              height: 44,
              color: Colors.white,
            ),
            TileNormal(
              title: Text(
                '拜访记录',
                style: TextStyle(
                  color: AppColors.DetailTextColor,
                  fontSize: AppFontSizes.Font15,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
              ),
              height: 40,
            ),
            Container(
              padding: EdgeInsets.only(bottom: 15),
              color: Colors.white,
              child: TextField(
                onChanged: (str) {
                  _visitorDetails = str;
                  print(_visitorDetails);
                },
                decoration: InputDecoration(
                  hintText: '请输入…',
                  hintStyle: TextStyle(
                    color: AppColors.PlaceholderTextColor,
                    fontSize: AppFontSizes.Font13,
                    fontFamily: AppFontFamilies.PingFangSC,
                    fontWeight: FontWeight.w500,
                  ),
                  contentPadding: EdgeInsets.fromLTRB(16, 13, 16, 13),
                  border: InputBorder.none,
                ),
                style: TextStyle(
                  color: AppColors.TextColor,
                  fontSize: AppFontSizes.Font13,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
                maxLines: 6,
                scrollPadding: EdgeInsets.all(0),
              ),
            ),
            GridViewAddImage(),
            Padding(padding: EdgeInsets.only(top: 36)),
            Container(
              height: 40,
              margin: EdgeInsets.fromLTRB(
                AppScreen.setWidth(29),
                0,
                AppScreen.setWidth(29),
                35,
              ),
              decoration: BoxDecoration(
                color: AppColors.MainColor,
                borderRadius: BorderRadius.circular(20),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(20),
                child: MaterialButton(
                  onPressed: () {
                    print('111');
                  },
                  child: Text(
                    '完成',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: AppFontSizes.Font17,
                      fontFamily: AppFontFamilies.PingFangSC,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
